Moveit2 Tutorial 3
Run Docker - Open a new terminal and run:
xhost +local:docker && sudo docker run -it --net=host --ipc=host --pid=host --env="DISPLAY=$DISPLAY" --env="QT_X11_NO_MITSHM=1" --env="XAUTHORITY=$XAUTH" --volume="$XAUTH:$XAUTH" -e LIBGL_ALWAYS_SOFTWARE=1 moveit/moveit2:main-jazzy-tutorial-source
Change the directory to hellow_moveit package
cd ~/ws_moveit/src/hello_moveit/
Open package.xml with nano
sudo nano package.xml
Add this line of code
<depend>moveit_visual_tools</depend>
It will look like this:
Press "Ctr + O" to write, press Enter to confirm , Press "Ctr +X" to exit it.
Open CMakeLists.txtl with nano
sudo nano CMakeLists.txt
find_package statements:find_package(moveit_visual_tools REQUIRED)
It will look like this:
ament_target_dependencies""moveit_visual_tools"
It will look like this:
Press "Ctr + O" to write, press Enter to confirm , Press "Ctr +X" to exit it.
Open hello_moveit.cpp with nano
sudo nano src/hello_moveit.cpp
add this line:
#include <moveit_visual_tools/moveit_visual_tools.h>
It will look like this:
Press "Ctr + O" to write, press Enter to confirm , Press "Ctr +X" to exit it.
cd ~/ws_moveit/ && colcon build --packages-select hello_moveit
cd ~/ws_moveit/ && source install/setup.bash
*Open a new tab of terminal, clicking this:
You will see new tab will be opened*
docker ps
**Copy your docker ID here!
sudo docker commit {docker_id} moveit/moveit2:main-jazzy-tutorial-source
This will save your work. If you are not doing it properly, you will lose your work!
***Now return to your "previous tab" running Docker, and exit it.
exit
Run Docker - Open a new terminal and run:
xhost +local:docker && sudo docker run -it --net=host --ipc=host --pid=host --env="DISPLAY=$DISPLAY" --env="QT_X11_NO_MITSHM=1" --env="XAUTHORITY=$XAUTH" --volume="$XAUTH:$XAUTH" -e LIBGL_ALWAYS_SOFTWARE=1 moveit/moveit2:main-jazzy-tutorial-source
Change the directory to hellow_moveit package
cd ~/ws_moveit/src/hello_moveit/
Open hello_moveit.cpp with nano
sudo nano src/hello_moveit.cpp
Add this line at the top:
#include <thread> // <---- add this to the set of includes at the top
It will look like this:
Add this line in the Main function:
// We spin up a SingleThreadedExecutor for the current state monitor to get
// information about the robot's state.
rclcpp::executors::SingleThreadedExecutor executor;
executor.add_node(node);
auto spinner = std::thread([&executor]() { executor.spin(); });
It will look like this:
Add this line at the end:
spinner.join(); // <--- Join the thread before exiting
It will look like this:
Press "Ctr + O" to write, press Enter to confirm , Press "Ctr +X" to exit it.
Open hello_moveit.cpp with nano
sudo nano src/hello_moveit.cpp
Add this code:
// Construct and initialize MoveItVisualTools
auto moveit_visual_tools =
moveit_visual_tools::MoveItVisualTools{ node, "base_link", rviz_visual_tools::RVIZ_MARKER_TOPIC,
move_group_interface.getRobotModel() };
moveit_visual_tools.deleteAllMarkers();
moveit_visual_tools.loadRemoteControl();
It will look like this:
Add this code:
// Create a closure for updating the text in rviz
auto const draw_title = [&moveit_visual_tools](auto text) {
auto const text_pose = [] {
auto msg = Eigen::Isometry3d::Identity();
msg.translation().z() = 1.0; // Place text 1m above the base link
return msg;
}();
moveit_visual_tools.publishText(text_pose, text, rviz_visual_tools::WHITE, rviz_visual_tools::XLARGE);
};
auto const prompt = [&moveit_visual_tools](auto text) { moveit_visual_tools.prompt(text); };
auto const draw_trajectory_tool_path =
[&moveit_visual_tools, jmg = move_group_interface.getRobotModel()->getJointModelGroup("manipulator")](
auto const trajectory) { moveit_visual_tools.publishTrajectoryLine(trajectory, jmg); };
It will look like this:
Add this code:
// Create a plan to that target pose
prompt("Press 'Next' in the RvizVisualToolsGui window to plan");
draw_title("Planning");
moveit_visual_tools.trigger();
It will look like this:
Modify the code below (Replace it by copy and paste):
// Execute the plan
if (success)
{
draw_trajectory_tool_path(plan.trajectory);
moveit_visual_tools.trigger();
prompt("Press 'next' in the RvizVisualToolsGui window to execute");
draw_title("Executing");
moveit_visual_tools.trigger();
move_group_interface.execute(plan);
}
else
{
draw_title("Planning Failed!");
moveit_visual_tools.trigger();
RCLCPP_ERROR(logger, "Planning failed!");
}
it will look like this:
Press "Ctr + O" to write, press Enter to confirm , Press "Ctr +X" to exit it.
colcon build the ROS package
cd ~/ws_moveit/ && colcon build --packages-select hello_moveit
cd ~/ws_moveit/ && source install/setup.bash
{Optional} If you have lost track of the code and encounter a compilation error, you can replace the entire code by copying and pasting this.
and colcon build the ROS package again
cd ~/ws_moveit/ && colcon build --packages-select hello_moveit
cd ~/ws_moveit/ && source install/setup.bash
*Open a new tab of terminal, clicking this:
You will see new tab will be opened*
docker ps
**Copy your docker ID here!
sudo docker commit {docker_id} moveit/moveit2:main-jazzy-tutorial-source
This will save your work. If you are not doing it properly, you will lose your work!
***Now return to your "previous tab" running Docker, and exit it.
exit
Run Docker - Open a new terminal and run:
xhost +local:docker && sudo docker run -it --net=host --ipc=host --pid=host --env="DISPLAY=$DISPLAY" --env="QT_X11_NO_MITSHM=1" --env="XAUTHORITY=$XAUTH" --volume="$XAUTH:$XAUTH" -e LIBGL_ALWAYS_SOFTWARE=1 moveit/moveit2:main-jazzy-tutorial-source
Run the RViz
ros2 launch moveit2_tutorials demo.launch.py
Uncheck “MotionPlanning” in the “Displays” tab to hide it. We aren’t going to be using the “MotionPlanning” plugin for this next part.
To add the buttons to interact with the prompts we added to our program open the dialog with the “Panels/Add New Panel” menu:
Finally, we need to add a Marker Array to render the visualizations we’ve added. Click on the “Add” Button in the “Displays” panel.
Scroll to the bottom of the items in the Displays panel and edit the topic that the new Marker Array is using to /visualization marker array.
You are now ready to run your new program with visualizations.
In a new terminal, go to the workspace, source the workspace, and run hello_moveit:
xhost +local:docker && sudo docker run -it --net=host --ipc=host --pid=host --env="DISPLAY=$DISPLAY" --env="QT_X11_NO_MITSHM=1" --env="XAUTHORITY=$XAUTH" --volume="$XAUTH:$XAUTH" -e LIBGL_ALWAYS_SOFTWARE=1 moveit/moveit2:main-jazzy-tutorial-source
ros2 run hello_moveit hello_moveit
You’ll notice that your program has stopped with a log that looks like this:
Click the Next button in RViz and see your application advance.
Go to Tutorial 4